﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using NguyenHoa.Domains;
using NguyenHoa.Data;

#endregion

namespace NguyenHoa.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="HtmlContentProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class HtmlContentProviderBaseCore : EntityProviderBase<NguyenHoa.Domains.HtmlContent, NguyenHoa.Domains.HtmlContentKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, NguyenHoa.Domains.HtmlContentKey key)
		{
			return Delete(transactionManager, key.Id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _id)
		{
			return Delete(null, _id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _id);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblLanguage key.
		///		FK_tblHtmlContent_tblLanguage Description: 
		/// </summary>
		/// <param name="_languageId"></param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public TList<HtmlContent> GetByLanguageId(System.Int32 _languageId)
		{
			int count = -1;
			return GetByLanguageId(_languageId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblLanguage key.
		///		FK_tblHtmlContent_tblLanguage Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_languageId"></param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		/// <remarks></remarks>
		public TList<HtmlContent> GetByLanguageId(TransactionManager transactionManager, System.Int32 _languageId)
		{
			int count = -1;
			return GetByLanguageId(transactionManager, _languageId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblLanguage key.
		///		FK_tblHtmlContent_tblLanguage Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_languageId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public TList<HtmlContent> GetByLanguageId(TransactionManager transactionManager, System.Int32 _languageId, int start, int pageLength)
		{
			int count = -1;
			return GetByLanguageId(transactionManager, _languageId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblLanguage key.
		///		fkTblHtmlContentTblLanguage Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_languageId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public TList<HtmlContent> GetByLanguageId(System.Int32 _languageId, int start, int pageLength)
		{
			int count =  -1;
			return GetByLanguageId(null, _languageId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblLanguage key.
		///		fkTblHtmlContentTblLanguage Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_languageId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public TList<HtmlContent> GetByLanguageId(System.Int32 _languageId, int start, int pageLength,out int count)
		{
			return GetByLanguageId(null, _languageId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblLanguage key.
		///		FK_tblHtmlContent_tblLanguage Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_languageId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public abstract TList<HtmlContent> GetByLanguageId(TransactionManager transactionManager, System.Int32 _languageId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblMenuType key.
		///		FK_tblHtmlContent_tblMenuType Description: 
		/// </summary>
		/// <param name="_typeId"></param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public TList<HtmlContent> GetByTypeId(System.Int32 _typeId)
		{
			int count = -1;
			return GetByTypeId(_typeId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblMenuType key.
		///		FK_tblHtmlContent_tblMenuType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_typeId"></param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		/// <remarks></remarks>
		public TList<HtmlContent> GetByTypeId(TransactionManager transactionManager, System.Int32 _typeId)
		{
			int count = -1;
			return GetByTypeId(transactionManager, _typeId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblMenuType key.
		///		FK_tblHtmlContent_tblMenuType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_typeId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public TList<HtmlContent> GetByTypeId(TransactionManager transactionManager, System.Int32 _typeId, int start, int pageLength)
		{
			int count = -1;
			return GetByTypeId(transactionManager, _typeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblMenuType key.
		///		fkTblHtmlContentTblMenuType Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_typeId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public TList<HtmlContent> GetByTypeId(System.Int32 _typeId, int start, int pageLength)
		{
			int count =  -1;
			return GetByTypeId(null, _typeId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblMenuType key.
		///		fkTblHtmlContentTblMenuType Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_typeId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public TList<HtmlContent> GetByTypeId(System.Int32 _typeId, int start, int pageLength,out int count)
		{
			return GetByTypeId(null, _typeId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblHtmlContent_tblMenuType key.
		///		FK_tblHtmlContent_tblMenuType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_typeId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.HtmlContent objects.</returns>
		public abstract TList<HtmlContent> GetByTypeId(TransactionManager transactionManager, System.Int32 _typeId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override NguyenHoa.Domains.HtmlContent Get(TransactionManager transactionManager, NguyenHoa.Domains.HtmlContentKey key, int start, int pageLength)
		{
			return GetById(transactionManager, key.Id, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_tblHtmlContent index.
		/// </summary>
		/// <param name="_id"></param>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.HtmlContent"/> class.</returns>
		public NguyenHoa.Domains.HtmlContent GetById(System.Int32 _id)
		{
			int count = -1;
			return GetById(null,_id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblHtmlContent index.
		/// </summary>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.HtmlContent"/> class.</returns>
		public NguyenHoa.Domains.HtmlContent GetById(System.Int32 _id, int start, int pageLength)
		{
			int count = -1;
			return GetById(null, _id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblHtmlContent index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.HtmlContent"/> class.</returns>
		public NguyenHoa.Domains.HtmlContent GetById(TransactionManager transactionManager, System.Int32 _id)
		{
			int count = -1;
			return GetById(transactionManager, _id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblHtmlContent index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.HtmlContent"/> class.</returns>
		public NguyenHoa.Domains.HtmlContent GetById(TransactionManager transactionManager, System.Int32 _id, int start, int pageLength)
		{
			int count = -1;
			return GetById(transactionManager, _id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblHtmlContent index.
		/// </summary>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.HtmlContent"/> class.</returns>
		public NguyenHoa.Domains.HtmlContent GetById(System.Int32 _id, int start, int pageLength, out int count)
		{
			return GetById(null, _id, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblHtmlContent index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.HtmlContent"/> class.</returns>
		public abstract NguyenHoa.Domains.HtmlContent GetById(TransactionManager transactionManager, System.Int32 _id, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#region _tblHtmlContent_GetIntroAtHomePage 
		
		/// <summary>
		///	This method wrap the '_tblHtmlContent_GetIntroAtHomePage' stored procedure. 
		/// </summary>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;HtmlContent&gt;"/> instance.</returns>
		public TList<HtmlContent> GetIntroAtHomePage(System.Int32? languageId)
		{
			return GetIntroAtHomePage(null, 0, int.MaxValue , languageId);
		}
		
		/// <summary>
		///	This method wrap the '_tblHtmlContent_GetIntroAtHomePage' stored procedure. 
		/// </summary>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;HtmlContent&gt;"/> instance.</returns>
		public TList<HtmlContent> GetIntroAtHomePage(int start, int pageLength, System.Int32? languageId)
		{
			return GetIntroAtHomePage(null, start, pageLength , languageId);
		}
				
		/// <summary>
		///	This method wrap the '_tblHtmlContent_GetIntroAtHomePage' stored procedure. 
		/// </summary>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;HtmlContent&gt;"/> instance.</returns>
		public TList<HtmlContent> GetIntroAtHomePage(TransactionManager transactionManager, System.Int32? languageId)
		{
			return GetIntroAtHomePage(transactionManager, 0, int.MaxValue , languageId);
		}
		
		/// <summary>
		///	This method wrap the '_tblHtmlContent_GetIntroAtHomePage' stored procedure. 
		/// </summary>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;HtmlContent&gt;"/> instance.</returns>
		public abstract TList<HtmlContent> GetIntroAtHomePage(TransactionManager transactionManager, int start, int pageLength , System.Int32? languageId);
		
		#endregion
		
		#region _tblHtmlContent_GetByTypeAndLanguage 
		
		/// <summary>
		///	This method wrap the '_tblHtmlContent_GetByTypeAndLanguage' stored procedure. 
		/// </summary>
		/// <param name="typeId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;HtmlContent&gt;"/> instance.</returns>
		public TList<HtmlContent> GetByTypeAndLanguage(System.Int32? typeId, System.Int32? languageId)
		{
			return GetByTypeAndLanguage(null, 0, int.MaxValue , typeId, languageId);
		}
		
		/// <summary>
		///	This method wrap the '_tblHtmlContent_GetByTypeAndLanguage' stored procedure. 
		/// </summary>
		/// <param name="typeId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;HtmlContent&gt;"/> instance.</returns>
		public TList<HtmlContent> GetByTypeAndLanguage(int start, int pageLength, System.Int32? typeId, System.Int32? languageId)
		{
			return GetByTypeAndLanguage(null, start, pageLength , typeId, languageId);
		}
				
		/// <summary>
		///	This method wrap the '_tblHtmlContent_GetByTypeAndLanguage' stored procedure. 
		/// </summary>
		/// <param name="typeId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;HtmlContent&gt;"/> instance.</returns>
		public TList<HtmlContent> GetByTypeAndLanguage(TransactionManager transactionManager, System.Int32? typeId, System.Int32? languageId)
		{
			return GetByTypeAndLanguage(transactionManager, 0, int.MaxValue , typeId, languageId);
		}
		
		/// <summary>
		///	This method wrap the '_tblHtmlContent_GetByTypeAndLanguage' stored procedure. 
		/// </summary>
		/// <param name="typeId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;HtmlContent&gt;"/> instance.</returns>
		public abstract TList<HtmlContent> GetByTypeAndLanguage(TransactionManager transactionManager, int start, int pageLength , System.Int32? typeId, System.Int32? languageId);
		
		#endregion
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;HtmlContent&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;HtmlContent&gt;"/></returns>
		public static TList<HtmlContent> Fill(IDataReader reader, TList<HtmlContent> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				NguyenHoa.Domains.HtmlContent c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("HtmlContent")
					.Append("|").Append((System.Int32)reader[((int)HtmlContentColumn.Id - 1)]).ToString();
					c = EntityManager.LocateOrCreate<HtmlContent>(
					key.ToString(), // EntityTrackingKey
					"HtmlContent",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new NguyenHoa.Domains.HtmlContent();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.Id = (System.Int32)reader[((int)HtmlContentColumn.Id - 1)];
					c.Name = (reader.IsDBNull(((int)HtmlContentColumn.Name - 1)))?null:(System.String)reader[((int)HtmlContentColumn.Name - 1)];
					c.Summary = (reader.IsDBNull(((int)HtmlContentColumn.Summary - 1)))?null:(System.String)reader[((int)HtmlContentColumn.Summary - 1)];
					c.Content = (System.String)reader[((int)HtmlContentColumn.Content - 1)];
					c.LanguageId = (System.Int32)reader[((int)HtmlContentColumn.LanguageId - 1)];
					c.TypeId = (System.Int32)reader[((int)HtmlContentColumn.TypeId - 1)];
					c.Status = (reader.IsDBNull(((int)HtmlContentColumn.Status - 1)))?null:(System.String)reader[((int)HtmlContentColumn.Status - 1)];
					c.CreatedDate = (System.DateTime)reader[((int)HtmlContentColumn.CreatedDate - 1)];
					c.CreatedBy = (reader.IsDBNull(((int)HtmlContentColumn.CreatedBy - 1)))?null:(System.String)reader[((int)HtmlContentColumn.CreatedBy - 1)];
					c.ModifiedDate = (reader.IsDBNull(((int)HtmlContentColumn.ModifiedDate - 1)))?null:(System.DateTime?)reader[((int)HtmlContentColumn.ModifiedDate - 1)];
					c.ModifiedBy = (reader.IsDBNull(((int)HtmlContentColumn.ModifiedBy - 1)))?null:(System.String)reader[((int)HtmlContentColumn.ModifiedBy - 1)];
					c.ApprovedDate = (reader.IsDBNull(((int)HtmlContentColumn.ApprovedDate - 1)))?null:(System.DateTime?)reader[((int)HtmlContentColumn.ApprovedDate - 1)];
					c.ApprovedBy = (reader.IsDBNull(((int)HtmlContentColumn.ApprovedBy - 1)))?null:(System.String)reader[((int)HtmlContentColumn.ApprovedBy - 1)];
					c.Tags = (reader.IsDBNull(((int)HtmlContentColumn.Tags - 1)))?null:(System.String)reader[((int)HtmlContentColumn.Tags - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="NguyenHoa.Domains.HtmlContent"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="NguyenHoa.Domains.HtmlContent"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, NguyenHoa.Domains.HtmlContent entity)
		{
			if (!reader.Read()) return;
			
			entity.Id = (System.Int32)reader[((int)HtmlContentColumn.Id - 1)];
			entity.Name = (reader.IsDBNull(((int)HtmlContentColumn.Name - 1)))?null:(System.String)reader[((int)HtmlContentColumn.Name - 1)];
			entity.Summary = (reader.IsDBNull(((int)HtmlContentColumn.Summary - 1)))?null:(System.String)reader[((int)HtmlContentColumn.Summary - 1)];
			entity.Content = (System.String)reader[((int)HtmlContentColumn.Content - 1)];
			entity.LanguageId = (System.Int32)reader[((int)HtmlContentColumn.LanguageId - 1)];
			entity.TypeId = (System.Int32)reader[((int)HtmlContentColumn.TypeId - 1)];
			entity.Status = (reader.IsDBNull(((int)HtmlContentColumn.Status - 1)))?null:(System.String)reader[((int)HtmlContentColumn.Status - 1)];
			entity.CreatedDate = (System.DateTime)reader[((int)HtmlContentColumn.CreatedDate - 1)];
			entity.CreatedBy = (reader.IsDBNull(((int)HtmlContentColumn.CreatedBy - 1)))?null:(System.String)reader[((int)HtmlContentColumn.CreatedBy - 1)];
			entity.ModifiedDate = (reader.IsDBNull(((int)HtmlContentColumn.ModifiedDate - 1)))?null:(System.DateTime?)reader[((int)HtmlContentColumn.ModifiedDate - 1)];
			entity.ModifiedBy = (reader.IsDBNull(((int)HtmlContentColumn.ModifiedBy - 1)))?null:(System.String)reader[((int)HtmlContentColumn.ModifiedBy - 1)];
			entity.ApprovedDate = (reader.IsDBNull(((int)HtmlContentColumn.ApprovedDate - 1)))?null:(System.DateTime?)reader[((int)HtmlContentColumn.ApprovedDate - 1)];
			entity.ApprovedBy = (reader.IsDBNull(((int)HtmlContentColumn.ApprovedBy - 1)))?null:(System.String)reader[((int)HtmlContentColumn.ApprovedBy - 1)];
			entity.Tags = (reader.IsDBNull(((int)HtmlContentColumn.Tags - 1)))?null:(System.String)reader[((int)HtmlContentColumn.Tags - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="NguyenHoa.Domains.HtmlContent"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="NguyenHoa.Domains.HtmlContent"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, NguyenHoa.Domains.HtmlContent entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Id = (System.Int32)dataRow["Id"];
			entity.Name = Convert.IsDBNull(dataRow["Name"]) ? null : (System.String)dataRow["Name"];
			entity.Summary = Convert.IsDBNull(dataRow["Summary"]) ? null : (System.String)dataRow["Summary"];
			entity.Content = (System.String)dataRow["Content"];
			entity.LanguageId = (System.Int32)dataRow["LanguageId"];
			entity.TypeId = (System.Int32)dataRow["TypeId"];
			entity.Status = Convert.IsDBNull(dataRow["Status"]) ? null : (System.String)dataRow["Status"];
			entity.CreatedDate = (System.DateTime)dataRow["CreatedDate"];
			entity.CreatedBy = Convert.IsDBNull(dataRow["CreatedBy"]) ? null : (System.String)dataRow["CreatedBy"];
			entity.ModifiedDate = Convert.IsDBNull(dataRow["ModifiedDate"]) ? null : (System.DateTime?)dataRow["ModifiedDate"];
			entity.ModifiedBy = Convert.IsDBNull(dataRow["ModifiedBy"]) ? null : (System.String)dataRow["ModifiedBy"];
			entity.ApprovedDate = Convert.IsDBNull(dataRow["ApprovedDate"]) ? null : (System.DateTime?)dataRow["ApprovedDate"];
			entity.ApprovedBy = Convert.IsDBNull(dataRow["ApprovedBy"]) ? null : (System.String)dataRow["ApprovedBy"];
			entity.Tags = Convert.IsDBNull(dataRow["Tags"]) ? null : (System.String)dataRow["Tags"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="NguyenHoa.Domains.HtmlContent"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">NguyenHoa.Domains.HtmlContent Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, NguyenHoa.Domains.HtmlContent entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region LanguageIdSource	
			if (CanDeepLoad(entity, "Language|LanguageIdSource", deepLoadType, innerList) 
				&& entity.LanguageIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.LanguageId;
				Language tmpEntity = EntityManager.LocateEntity<Language>(EntityLocator.ConstructKeyFromPkItems(typeof(Language), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.LanguageIdSource = tmpEntity;
				else
					entity.LanguageIdSource = DataRepository.LanguageProvider.GetById(transactionManager, entity.LanguageId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'LanguageIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.LanguageIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.LanguageProvider.DeepLoad(transactionManager, entity.LanguageIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion LanguageIdSource

			#region TypeIdSource	
			if (CanDeepLoad(entity, "MenuType|TypeIdSource", deepLoadType, innerList) 
				&& entity.TypeIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.TypeId;
				MenuType tmpEntity = EntityManager.LocateEntity<MenuType>(EntityLocator.ConstructKeyFromPkItems(typeof(MenuType), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.TypeIdSource = tmpEntity;
				else
					entity.TypeIdSource = DataRepository.MenuTypeProvider.GetById(transactionManager, entity.TypeId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'TypeIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.TypeIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.MenuTypeProvider.DeepLoad(transactionManager, entity.TypeIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion TypeIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the NguyenHoa.Domains.HtmlContent object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">NguyenHoa.Domains.HtmlContent instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">NguyenHoa.Domains.HtmlContent Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, NguyenHoa.Domains.HtmlContent entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region LanguageIdSource
			if (CanDeepSave(entity, "Language|LanguageIdSource", deepSaveType, innerList) 
				&& entity.LanguageIdSource != null)
			{
				DataRepository.LanguageProvider.Save(transactionManager, entity.LanguageIdSource);
				entity.LanguageId = entity.LanguageIdSource.Id;
			}
			#endregion 
			
			#region TypeIdSource
			if (CanDeepSave(entity, "MenuType|TypeIdSource", deepSaveType, innerList) 
				&& entity.TypeIdSource != null)
			{
				DataRepository.MenuTypeProvider.Save(transactionManager, entity.TypeIdSource);
				entity.TypeId = entity.TypeIdSource.Id;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region HtmlContentChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>NguyenHoa.Domains.HtmlContent</c>
	///</summary>
	public enum HtmlContentChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Language</c> at LanguageIdSource
		///</summary>
		[ChildEntityType(typeof(Language))]
		Language,
			
		///<summary>
		/// Composite Property for <c>MenuType</c> at TypeIdSource
		///</summary>
		[ChildEntityType(typeof(MenuType))]
		MenuType,
		}
	
	#endregion HtmlContentChildEntityTypes
	
	#region HtmlContentFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;HtmlContentColumn&gt;"/> class
	/// that is used exclusively with a <see cref="HtmlContent"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class HtmlContentFilterBuilder : SqlFilterBuilder<HtmlContentColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the HtmlContentFilterBuilder class.
		/// </summary>
		public HtmlContentFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the HtmlContentFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public HtmlContentFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the HtmlContentFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public HtmlContentFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion HtmlContentFilterBuilder
	
	#region HtmlContentParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;HtmlContentColumn&gt;"/> class
	/// that is used exclusively with a <see cref="HtmlContent"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class HtmlContentParameterBuilder : ParameterizedSqlFilterBuilder<HtmlContentColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the HtmlContentParameterBuilder class.
		/// </summary>
		public HtmlContentParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the HtmlContentParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public HtmlContentParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the HtmlContentParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public HtmlContentParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion HtmlContentParameterBuilder
	
	#region HtmlContentSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;HtmlContentColumn&gt;"/> class
	/// that is used exclusively with a <see cref="HtmlContent"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class HtmlContentSortBuilder : SqlSortBuilder<HtmlContentColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the HtmlContentSqlSortBuilder class.
		/// </summary>
		public HtmlContentSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion HtmlContentSortBuilder
	
} // end namespace
